Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ModifierComparer use type references instead of definition #7557

Merged
merged 1 commit into from
Jun 24, 2021

Conversation

ericstj
Copy link
Member

@ericstj ericstj commented Jun 23, 2021

When comparing definitions this was failing if the type couldn't be resolved,
for instance if a type-forwarded dependency was missing or references
were specified at all.

This was inconsistent with our other parameter comparisons which just
evaluate the compare the type reference as a string without considering
assembly.

This does raise a concerning issue, that APICompat doesn't actually
evaluate assembly equivalence of parameters but that's an existing
problem.

Fixes #2102, #7511.
Related #2136

cc @utpilla

When comparing definitions this was failing if the type couldn't be resolved,
for instance if a type-forwarded dependency was missing or references
were specified at all.

This was inconsistent with our other parameter comparisons which just
evaluate the compare the type reference as a string without considering
assembly.

This does raise a concerning issue, that APICompat doesn't actually
evaluate assembly equivalence of parameters but that's an existing
problem.
@ericstj ericstj requested review from dougbu and safern June 23, 2021 23:35
Copy link
Member

@safern safern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

This does raise a concerning issue, that APICompat doesn't actually
evaluate assembly equivalence of parameters but that's an existing
problem.

For that we can discuss to add this kind of validation for the new API Compat.

Copy link
Member

@dougbu dougbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is my bad because I added ModifierComparer in d6dd7a0#diff-ab264297f1e0d7296c8d69384a224e589d95ced59d203663d968dcc20f7d1e13R131

I'm slightly concerned this isn't the only instance of the problem because I did a lot of copying and pasting in #4585 Pretty sure I copied most of that class from somewhere else but have no idea where…

@@ -144,7 +144,7 @@ public bool Equals(ICustomModifier x, ICustomModifier y)
}

return x.IsOptional == y.IsOptional &&
TypeComparer.Equals(x.Modifier.ResolvedType, y.Modifier.ResolvedType);
TypeComparer.Equals(x.Modifier, y.Modifier);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this allow both ICustomModifiers to be unresolved but disallow one or the other (and not both) to be resolved❔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just using the type-reference to do the comparison so it's irrelevant if either type is/can be resolved. This is consistent with how we already compare parameter types.

@ericstj
Copy link
Member Author

ericstj commented Jun 24, 2021

@dougbu you did a solid by fixing the original issue, this just tweaks your fix to not require TypeDefinitions to be equal. I think this is the only place you introduced that's doing TypeDefinition comparisons. I didn't see any other places where we were doing this (looking for uses of ResolvedType).

@ericstj ericstj merged commit a68ec1e into dotnet:main Jun 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ApiCompat: errors when using 'in' modifier
3 participants